<template>
  <div class="home">
    <HelloWorld msg="Welcome to Your Vue.js App" @clickFun="handleEvent"/>
    <s-input v-model="txt" type="input"></s-input>
    <button @click="test2">dispatch</button>
  </div>
</template>

<script>
// @ is an alias to /src
import Emitter from '../mixin/emitter'
import HelloWorld from '@/views/HelloWorld.vue'

export default {
  name: 'Home',
  components: {
    HelloWorld
  },
  mixins: [ Emitter ],
  data(){
    return{
      txt:''
    }
  },
  mounted(){
    this.$on('test1',(val)=>{
      console.log('父组件接受的dispatch',val)
    })
    this.sortVersion(["1.45.0","1.5","6","3.3.3.3.3"])
    console.log( this.sortVersion(["1.45.0","1.5","6","3.3.3.3.3"]))
  },
  methods: {
    sortVersion(list){
      return list.sort((a,b)=>{
        let aa= a.split(".")
        let bb= b.split(".")
        let length = aa.length>bb.length?aa.length:bb.length
        for(var i =0;i<length;i++){
          let x= aa[i] || 0
          let y = bb[i] || 0
          if(x-y !==0)return x-y
        }
      })
    },
    handleEvent(text){
      console.log('父组件调用了这个方法,拿到的值是',text)
    },
     test2(){
      this.broadcast('SButton','test','子组件触发dispatch事件---')
      // console.log('vue2已经废弃')
    }
  },
}
</script>
